package algotithm.leetcode.bit.test1720;

/**
 * @author 25068
 * @Date 2021/5/6 23:37
 * @Title 1720. 解码异或后的数组
 */
public class Solution {

    public static void main(String[] args) {
        int[] encoded = {1,2,3};
        int first = 1;
        Solution solution = new Solution();
        int[] decode = solution.decode(encoded, first);
        for (int arr : decode) {
            System.out.print(arr + " ");
        }
    }

    public int[] decode(int[] encoded, int first) {
        int n = encoded.length + 1;
        int[] arr = new int[n];
        arr[0] = first;
        for (int i = 1; i < n; i++) {
            arr[i] = arr[i - 1] ^ encoded[i - 1];
        }
        return arr;
    }
}
